module TclBot
  module Commands
    module WordCommand
      WORDS_FILE = "/usr/share/dict/words"
      
      def tcl_word(pattern = "")
        matches = words.grep(Regexp.new(pattern))
        matches[rand(matches.length)]
      end
      
      protected
        def words
          @words ||= IO.readlines(WORDS_FILE).each { |word| word.chomp! }
        end
    end
  end
end
